var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = void 0);
var t = require("../../@babel/runtime/helpers/classCallCheck"),
  a = require("../../@babel/runtime/helpers/createClass"),
  n = require("../../@babel/runtime/helpers/inherits"),
  i = require("../../@babel/runtime/helpers/createSuper"),
  o = e(require("../common/EventDispatcher.js")),
  r = e(require("../utils/gps")),
  s = (function (e) {
    n(s, e);
    var o = i(s);
    function s() {
      var e,
        a = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
      return (
        t(this, s),
        ((e = o.call(this)).started = !1),
        (e.wxApp = a.wxApp),
        (e.onLocationChangeHandler = function (t) {
          if (e.started) {
            var a = r.default.gcj_decrypt(t.latitude, t.longitude),
              n = {
                gcjLat: t.latitude,
                gcjLon: t.longitude,
                latitude: a.lat,
                longitude: a.lon,
                accuracy: t.accuracy,
                speed: t.speed,
                timestamp: new Date().getTime(),
              },
              i = r.default.gpsToLl3857([a.lon, a.lat]);
            (n.x = i[0]),
              (n.y = i[1]),
              e.emit("geo_positionChanged", { value: n });
          } else e.stopLocationChangeListener();
        }),
        e
      );
    }
    return (
      a(s, [
        {
          key: "start",
          value: function () {
            (this.started = !0), this.startLocationChangeListener();
          },
        },
        {
          key: "stop",
          value: function () {
            (this.started = !1), this.stopLocationChangeListener();
          },
        },
        {
          key: "startLocationChangeListener",
          value: function () {
            var e = this;
            this.started
              ? wx.startLocationUpdate({
                  success: function (t) {
                    e.started
                      ? wx.onLocationChange(e.onLocationChangeHandler)
                      : e.stopLocationChangeListener();
                  },
                  complete: function (e) {},
                })
              : this.stopLocationChangeListener();
          },
        },
        {
          key: "stopLocationChangeListener",
          value: function () {
            wx.offLocationChange &&
              wx.offLocationChange(this.onLocationChangeHandler),
              wx.stopLocationUpdate();
          },
        },
      ]),
      s
    );
  })(o.default);
exports.default = s;
